 # -*- coding: UTF-8 -*- 
import sys
from service import *
from login import LoginMainWindow
from PyQt5 import QtWidgets



book_list = [
    {
        "title":"红楼梦",
        "isbn":"9787020002207",
        "author":"曹雪芹",
        "count": 1
    },
    {
        "title":"活着",
        "isbn":"9787506365437",
        "author":"余华",
        "count": 1
    },
]

def LMS_init():
    us = UserService()
    ad = us.getUser("admin")
    if not ad:
        us.addUser("admin", "123456", "admin@lms.com", "admin")
        us.addUser("ling", "123456", "ling@lms.com", "user")

    bs = BookService()
    bc = bs.getBookCount()
    if bc == 0:
        for i in book_list:
            bs.addBook(i["title"], i["isbn"], i["author"], i["count"])

    lms = LMSService()
    count = lms.getLmsCount()
    if count == 0:
        lms.addLms("张洋铭-凌建-图书管理系统")

if __name__ == "__main__":
    Base.metadata.create_all(engine)
    LMS_init()
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = LoginMainWindow(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())







# if __name__ == "__main__":
#     print("start...")
#     Base.metadata.create_all(engine)
#     LMS_init()
#     lmss = LMSService()
#     print(lmss.getName())
#     bs = BookService()
#     for i in bs.getBookList():
#         print(i.title)
#     print("lms start...")
#     us = UserService()
#     us.addUser("ling","123456","ling@lms.com")

    # print(lmss.login("admin", "123456"))
    # borrowsvc = BorrowService()
    # borrowsvc.borrowBook(1,1)
    # borrowsvc.returnBook(1,1)